package com.goldsprite.spinelearn.examples.gfsm.states;

import com.goldsprite.gdxcore.gfsm.State;
import com.goldsprite.spinelearn.examples.AnimType;
import com.goldsprite.spinelearn.examples.gfsm.SpineStateMachine;

public class SpineMoveState extends State<SpineStateMachine> {
	private int lastFacing;

	@Override
	public boolean canEnter() {
		return fsm.getInput().isSafeMoving();
	}

	@Override
	public boolean canExit() {
		return !fsm.getInput().isSafeMoving();
	}

	@Override
	public void enter() {
		lastFacing = fsm.getEntity().getFacing();
		fsm.getEntity().playAnim(AnimType.MOVE, true);
		System.out.println("进入移动状态");
	}

	@Override
	public void running() {
		if(fsm.getEntity().getFacing() != lastFacing){
			fsm.getEntity().playAnim(AnimType.MOVE, true);
			lastFacing = fsm.getEntity().getFacing();
		}
		fsm.getEntity().move(fsm.getInput().getMoveDirection());
	}
}
